package top.frsf.zombies;

import top.frsf.GamePanel;
import top.frsf.plants.PlantsObject;
import top.frsf.utils.ZomState;

import java.awt.*;

/**
 * @BelongsProject: MiniPZ
 * @BelongsPackage: top.frsf.zombies
 * @Author: FRSF
 * @CreateTime: 2022-09-10  15:43
 * @Description: 普通zom
 * @Version: 1.0
 */
public class NormalZom extends ZomObject {


    static {
        normal = new Image[21];
        attack = new Image[21];
        Toolkit toolkit = GamePanel.tKit;
        for (int i = 0; i < 21; i++) {
            normal[i] = toolkit.getImage("src/main/resources/zombies/normal/" +
                    "Frame" + i + ".png");
            attack[i] = toolkit.getImage("src/main/resources/zombies/nor_attack/" +
                    "Frame" + i + ".png");
        }
    }


    public NormalZom(String img, int x, int y, int width, int height) {
        super(img, x, y, width, height, 100, 10);
    }

    @Override
    public void move() {
        if (GamePanel.fps % 3 == 1)
            setX(getX() - 1);
    }

    @Override
    public void downHP(int hp) {
        super.hp -= hp;
    }

    @Override
    public void paintSelf(Graphics g) {
        g.setColor(Color.ORANGE);
        g.drawRect(getX(), getY(), getWidth(), getHeight());

        state = ZomState.MOVE;
        // 植物列表遍历
        for (PlantsObject plant : GamePanel.plaStart.plantList) {
            if (getRec().contains(plant.getRec().getCenterX(), plant.getRec().getCenterY())) {
                // 该植物处于zom攻击范围，开启攻击模式
                state = ZomState.ATTACK;
                if (GamePanel.fps % 60 == 1)
                    plant.downHP(heartHP);
                break;
            }
        }

        if (state == ZomState.MOVE) {
            // 移动状态
            delayMovie(count, normal, g, getX(), getY(), 5);
            move();
        }
        if (state == ZomState.ATTACK) {
            // 攻击状态
            delayMovie(attackCount, attack, g, getX(), getY(), 5);
        }

        // 僵尸血量小于0
        if (hp <= 0) {
            GamePanel.zomStart.deadZomList.add(this);
        }
    }
}
